<?php

namespace backend\models;

use Yii;
use backend\models\Image;

/**
 * This is the model class for table "user_comment".
 *
 * @property integer $id
 * @property string $content_type
 * @property integer $content_id
 * @property integer $send_uid
 * @property integer $send_time
 * @property integer $comment_id
 * @property integer $like
 * @property string $comment
 */
class UserComment extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_comment';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['content_id', 'send_uid', 'send_time', 'comment_id', 'like'], 'integer'],
            [['comment'], 'string'],
            [['content_type'], 'string', 'max' => 64]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '评论ID',
            'content_type' => '类型',
            'content_id' => '商品ID',
            'send_uid' => '评论用户',
            'send_time' => '评论时间',
            'comment_id' => '评价层级',
            'like' => 'Like',
            'comment' => '评论',
            'view_img'=>'缩略图'
        ];
    }
    
    //获取套装的缩略图
    public function getSetImage()
    {
        if(empty(Taozhuang::findOne(['sid'=>$this->content_id]))){
            return '';
        }
        $imgId = Taozhuang::findOne(['sid'=>$this->content_id])->img_small_id;
        return Image::findOne(['id'=>$imgId])->url;
    }
    //获取单品的缩略图
    public function getItemImage()
    {
        if(empty(SysItem::findOne(['id'=>$this->content_id]))){
            return '';
        }
        $imgId = SysItem::findOne(['id'=>$this->content_id])->img_small_id;
        return Image::findOne(['id'=>$imgId])->url;
    }
}
